<!doctype html>
<html lang="en">
<head>
    @include('web.layout.head')
    <link rel="stylesheet" href="{{mix('/css/web/user/shop_design.css')}}">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>
<body>

@include('web.layout.header')
@include('web.layout.user_tab')
<div class="base_member_content">
    <div class="w1200">
      @include('web.layout.seller_nav')
      <div class="nav_right flr">
            <div class="base_content">
                <div class="line_title">自定义分类</div>
                <div class="my-subnav f-cb">
                    <ul>
                        <li>
                            <a href="{{asset('/member/seller/shop_design_templet')}}" class="jm_hover">
                                模板选择
                            </a><i></i>
                        </li>
                        <li>
                            <a href="{{asset('/member/seller/design')}}" class="jm_hover">
                                banner设置
                            </a><i></i>
                        </li>
                        <li class="cur">
                            <a href="{{asset('/member/seller/shop_design_custom')}}" class="jm_hover">
                                自定义分类
                            </a><i></i>
                        </li>
                    </ul>
                </div>
                <div class="tit_box">
                    <h2>请编辑产品分类</h2>
                    <a class="fr add_classify">+ 添加分类</a>
                </div>
                <div class="table">
                    <table>
                        <tbody>
                            @foreach($list as $k=>$v)
                            <tr class="tr_box_{{$v['id']}}">
                                <td><span class="data_text_{{$v['id']}}">{{$v['name']}}</span></td>
                                <td  width="200">
                                      <a class="btn_edit" data-id="{{$v['id']}}">编辑</a>
                                      <font>|</font>
                                      <a class="btn_del" data-id="{{$v['id']}}">删除</a>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="bg_h"></div>
<div class="delivery_bombbox">
    <div class="h_top"><h2>自定义分类</h2><a class="close_box">×</a></div>
    <div class="fl shu_box">
        <input type="text" name="classify_name" title="" class="classify_name" value="">
        <p class="jm_ts">分类名称为唯一且不能重名</p>
        {{--<span class="jm_error" style="display: inline;clear: both;"></span>--}}
    </div>
    <div class="btn_box">
        <div class="btn_confirm fr classify_confirm" data-id = "1">确定</div>
        <div class="btn_cancel fr close_box">取消</div>
    </div>
</div>
@include('web.layout.footer')
<script type="text/javascript">
$(function(){
    var btn_type;
    var id;
  //添加自定义分类
  $('.add_classify').click(function(){

      $('.jm_ts').css('color','#999');
      $('.bg_h').show();
      $('.delivery_bombbox').show();
      btn_type='add';
   });
  //编辑
  $('.btn_edit').click(function(){
      $('.jm_ts').css('color','#999');
      var edit_text=$(this).parent().prev().text();
      id = $(this).attr('data-id');
      $('.bg_h').show();
      $('.delivery_bombbox').show();
      $('.classify_name').val(edit_text);
      btn_type='edit';

   });
  $('.close_box').click(function(){
      $('.classify_name').val('');
      $('.bg_h').hide();
      $('.delivery_bombbox').hide();
  });
  //删除
  $('.btn_del').click(function(){
      var del_id = $(this).attr('data-id');
      layer.confirm('确认删除？', {
          btn: ['确认', '取消'] //可以无限个按钮
      }, function (index) {
          $.ajax({
              url: "{{ url('member/seller/shop_design_custom') }}/"+del_id,
              type: 'delete',
              dataType: 'json',
              data: {},
              success: function (data) {
                  if (0 == data.code) {
                      $('.tr_box_'+del_id).remove();
                      layer.alert("删除成功", {
                          icon: 1
                      }
//                              , function () {
//                          location.reload();
//                      }
                      );
                  } else {
                      layer.alert(data.message, {
                          icon: 2
                      });
                  }
              }
          });
      }, function (index, layero) {
          layer.close(index);
      });
  });
  //设为默认
  $('.btn_default').click(function(){
      var derault_id = $(this).attr('data-id');
      layer.confirm('确认设为为默认合同？', {
          btn: ['确认', '取消'] //可以无限个按钮
      }, function (index) {
          $.ajax({
              url: "",
              type: 'post',
              dataType: 'json',
              data: {'id': derault_id},
              success: function (data) {
                  if (0 == data.code) {
                      layer.alert("修改成功", {

                          icon: 1
                      }, function () {
                          location.reload();
                      });
                  } else {
                      layer.alert(data.message, {
                          icon: 2
                      });
                  }
              }
          });
      }, function (index, layero) {
          layer.close(index);
      });
  });
  //点击确定
  $('.classify_confirm').click(function(){
      var choice_id = id;
      if($.trim($('.classify_name').val()) == ''){
           layer.alert('请输入分类名称', {icon: 2});
           return false;
      }

      if(btn_type=='add'){
          $.ajax({
              url: "{{ url('member/seller/shop_design_custom') }}",
              type: 'post',
              dataType: 'json',
              data: {name:$('.classify_name').val()},
              success: function (data) {
                  if (0 == data.code) {
                      layer.alert("添加成功", {
                          icon: 1
                      }, function () {
                          location.reload();
                      });
                  } else {
                      layer.alert(data.message, {
                          icon: 2
                      });
                  }
              },
              error:function (res) {
//                  console.log(res);
                  $('.jm_ts').html(res.responseJSON.name[0]);
                  $('.jm_ts').css('color','red');
              }
            });
      }else{
          var data_text=$('.classify_name').val();
          $.ajax({
              url: "{{ url('member/seller/shop_design_custom') }}/"+choice_id,
              type: 'put',
              dataType: 'json',
              data: {name:data_text},
              success: function (data) {
                  if (0 == data.code) {
                      $('.data_text_'+choice_id).text(data_text);
                      $('.classify_name').val('');
                      $('.bg_h').hide();
                      $('.delivery_bombbox').hide();
                      layer.alert("修改成功", {
                          icon: 1
                      }
//                               , function () {
//                           location.reload();
//                       }
                      );
                  } else {
                      layer.alert(data.message, {
                          icon: 2
                      });
                  }
              },
              error:function (res) {
                  //console.log();
                  $('.jm_ts').html(res.responseJSON.name[0]);
                  $('.jm_ts').css('color','red');
              }
            });
      }

  });

})
</script>
</body>
</html>